With the 'clicked' attribute you can set a script file that is called when a block next to the block is changing. You can use world and origin for your script.
neighborchanged="loader.loadScript('xyz.script');";